package com.tanjie.blackbean.web.component;

import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author: tanjie
 * @date: 2022-04-29
 **/
@Component
public class LocalThreadMap {

    // jdk建议将 ThreadLocal 定义为 private static ，这样就不会有弱引用，内存泄漏的问题了
    private final static ThreadLocal<Map<String, Object>> mapThreadLocal = new ThreadLocal<>();

    // 获取当前线程的存的变量
    public Map<String, Object> get() {
        return mapThreadLocal.get();
    }

    // 设置当前线程的存的变量
    public void set(Map<String, Object> map) {
        mapThreadLocal.set(map);
    }

    // 移除当前线程的存的变量
    public void remove() {
        mapThreadLocal.remove();
    }

}
